/** \file ChaikinMoneyFlow_t.cc 
 * Test definitions for the ChaikinMoneyFlow function
 *
 * (C) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: ChaikinMoneyFlow_t.cc 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */


#include "ChaikinMoneyFlow.hpp"
#include <vector>
#include <list>
#include "Stock.hpp"
#include "SecurityAdaptor.hpp"
#include "TestHarness.hh"

using namespace std;
using namespace TC;

namespace {

  const unsigned DataSize = 58;

  const double data_hi[DataSize] = {
    8.6250, 8.6250, 8.6250, 8.7500, 8.7500, 8.5625, 8.5000, 
    8.3125, 8.0625, 8.0625, 7.8750, 7.5000, 7.3125, 7.4375,
    7.5625, 7.5625, 7.7500, 7.6250, 7.7500, 7.8750, 8.1875,
    8.5000, 8.3125, 8.3750, 8.2500, 8.5000, 8.1250, 8.1250,
    7.8125, 7.6250, 7.5625, 7.5000, 7.5000, 7.5000, 7.3750,
    7.3125, 7.1250, 7.3750, 7.2500, 7.3125, 7.4375, 7.4375,
    7.6875, 7.5625, 7.6250, 7.4375, 7.0000, 6.6250, 6.5000,
    6.8750, 6.8750, 6.9375, 7.0625, 7.1875, 7.0625, 7.0625,
    7.0000, 7.0000 };

  const double data_lo[DataSize] = {
    8.3125, 8.4375, 8.4375, 8.6250, 8.4375, 8.5000, 8.1875,
    8.0000, 8.0000, 7.9375, 7.3750, 7.0000, 7.0000, 7.3125,
    7.2500, 7.4375, 7.3750, 7.5000, 7.6250, 7.6875, 7.8750,
    8.2500, 8.1250, 8.1250, 8.1250, 8.1250, 7.8750, 7.6250,
    7.5625, 7.3750, 7.3125, 7.3750, 7.3750, 7.3125, 7.1875,
    7.0000, 6.9375, 7.1250, 6.9375, 7.0625, 7.2500, 7.3125,
    7.5000, 7.2500, 7.4375, 6.8750, 6.5000, 6.2500, 6.3125,
    6.5000, 6.6875, 6.8125, 6.9375, 7.0000, 7.0000, 6.9375,
    6.8750, 6.8750 };

  const double data_cls[DataSize] = {
    8.6250, 8.5000, 8.6250, 8.7500, 8.5000, 8.5000, 8.3125,
    8.0000, 8.0625, 8.0000, 7.5625, 7.0625, 7.3125, 7.3750,
    7.5000, 7.5625, 7.5625, 7.6250, 7.6875, 7.8750, 8.1250,
    8.2500, 8.3125, 8.1250, 8.1875, 8.1250, 8.0000, 7.6875,
    7.6250, 7.4375, 7.4375, 7.5000, 7.4375, 7.3750, 7.3125,
    7.0625, 7.1250, 7.1875, 7.1250, 7.1875, 7.4375, 7.4375,
    7.5625, 7.3750, 7.5000, 6.9375, 6.5625, 6.4375, 6.5000,
    6.7500, 6.8750, 6.9375, 7.0000, 7.0625, 7.0625, 7.0000,
    7.0000, 6.8750 };


  const long data_vol[DataSize] = {
    4494, 2090, 1306, 4242, 2874, 598, 2668, 19008, 6712, 1924,
    10340, 11910, 3474, 3112, 6898, 2448, 8464, 3996, 2754, 3138,
    5204, 7552, 1798, 2348, 2498, 2498, 2348, 3710, 1346, 4030,
    3034, 2308, 1584, 1320, 2746, 3246, 3948, 1840, 2454, 698, 2008,
    1852, 3704, 2484, 2206, 3072, 5870, 7402, 2524, 2674, 1236, 
    1394, 2870, 1160, 458, 688, 948, 1246 };


  const double data_expect[DataSize] = {
    0, 0, 0, 0, 0.50786, 0.22763, 0.23032, -0.59959, -0.47558, 
    -0.43441, -0.37918, -0.47728, -0.03875, -0.26149, -0.10927,
    0.04053, 0.41240, 0.42471, 0.43090, 0.46067, 0.43540,
    0.11943, 0.02477, -0.09190, -0.25668, -0.63496, -0.26527,
    -0.56921, -0.48012, -0.57196, -0.37811, -0.21919, -0.03089,
    -0.01197, 0.25321, 0.07459, 0.19275, 0.11876, 0.17469, 0.12893,
    0.50482, 0.38757, 0.29079, 0.19808, 0.11369, -0.22557, -0.53407,
    -0.38148, -0.23741, -0.15674, 0.01263, 0.39694, 0.56509, 0.33583,
    0.37951, 0.22303, 0.16645, -0.05037 };



}

TEST(ChaikinMoneyFlowTest, Base)
{
  StockDef s;
  list<StockDef> stocks;
  vector<double> result;
     
  for(unsigned i=0; i<DataSize; ++i) {
    s.setHi(static_cast<StockDef::Price_t>(data_hi[i]));
    s.setLo(static_cast<StockDef::Price_t>(data_lo[i]));
    s.setCls(static_cast<StockDef::Price_t>(data_cls[i]));
    s.setVol(static_cast<StockDef::Volume_t>(data_vol[i]));
    stocks.push_back(s);
  }

  ChaikinMoneyFlow(stocks.begin(), stocks.end(), 
                   back_inserter(result),
                   5,
                   SecurityAdaptor<StockDef>());

  TC_TEST(result.size()==DataSize);
  
  PrintElements(result, "ChaikinMoneyFlow");

  for(unsigned i=0; i<DataSize; ++i)
    if(data_expect[i] > 0)
      TC_TESTFP(data_expect[i], result[i]);

}

  



